<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Writers - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.log.writers.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.log.writers.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.log.overview.html">Overview</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.log.html">Zend_Log</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.log.formatters.html">Formatters</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.log.writers" class="section"><div class="info"><h1 class="title">Writers</h1></div>
    

    <p class="para">
        A Writer is an object that inherits from <span class="classname">Zend_Log_Writer_Abstract</span>.
        A Writer&#039;s responsibility is to record log data to a storage backend.
    </p>

    <div class="section" id="zend.log.writers.stream"><div class="info"><h1 class="title">Writing to Streams</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Log_Writer_Stream</span> sends log
            data to a <a href="http://www.php.net/stream" class="link external">&raquo; PHP stream</a>.
        </p>

        <p class="para">
            To write log data to the <acronym class="acronym">PHP</acronym> output buffer, use the URL
            <var class="filename">php://output</var>. Alternatively, you can send log data directly to a
            stream like <b><tt>STDERR</tt></b> (<var class="filename">php://stderr</var>).
        </p>

        <pre class="programlisting brush: php">
$writer = new Zend_Log_Writer_Stream(&#039;php://output&#039;);
$logger = new Zend_Log($writer);

$logger-&gt;info(&#039;Informational message&#039;);
</pre>


        <p class="para">
            To write data to a file, use one of the
            <a href="http://www.php.net/manual/en/wrappers.php#wrappers.file" class="link external">&raquo; Filesystem
            URLs</a>:
        </p>

        <pre class="programlisting brush: php">
$writer = new Zend_Log_Writer_Stream(&#039;/path/to/logfile&#039;);
$logger = new Zend_Log($writer);

$logger-&gt;info(&#039;Informational message&#039;);
</pre>


        <p class="para">
            By default, the stream opens in the append mode (&quot;a&quot;).
            To open it with a different mode, the <span class="classname">Zend_Log_Writer_Stream</span>
            constructor accepts an optional second parameter for the mode.
        </p>

        <p class="para">
            The constructor of <span class="classname">Zend_Log_Writer_Stream</span> also accepts an
            existing stream resource:
        </p>

        <pre class="programlisting brush: php">
$stream = @fopen(&#039;/path/to/logfile&#039;, &#039;a&#039;, false);
if (! $stream) {
    throw new Exception(&#039;Failed to open stream&#039;);
}

$writer = new Zend_Log_Writer_Stream($stream);
$logger = new Zend_Log($writer);

$logger-&gt;info(&#039;Informational message&#039;);
</pre>


        <p class="para">
            You cannot specify the mode for existing stream resources. Doing so
            causes a <span class="classname">Zend_Log_Exception</span> to be thrown.
        </p>
    </div>

    <div class="section" id="zend.log.writers.database"><div class="info"><h1 class="title">Writing to Databases</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Log_Writer_Db</span> writes log information to a database table
            using <span class="classname">Zend_Db</span>. The constructor of
            <span class="classname">Zend_Log_Writer_Db</span> receives a
            <span class="classname">Zend_Db_Adapter</span> instance, a table name, and a mapping of database
            columns to event data items:
        </p>

        <pre class="programlisting brush: php">
$params = array (&#039;host&#039;     =&gt; &#039;127.0.0.1&#039;,
                 &#039;username&#039; =&gt; &#039;malory&#039;,
                 &#039;password&#039; =&gt; &#039;******&#039;,
                 &#039;dbname&#039;   =&gt; &#039;camelot&#039;);
$db = Zend_Db::factory(&#039;PDO_MYSQL&#039;, $params);

$columnMapping = array(&#039;lvl&#039; =&gt; &#039;priority&#039;, &#039;msg&#039; =&gt; &#039;message&#039;);
$writer = new Zend_Log_Writer_Db($db, &#039;log_table_name&#039;, $columnMapping);

$logger = new Zend_Log($writer);

$logger-&gt;info(&#039;Informational message&#039;);
</pre>


        <p class="para">
            The example above writes a single row of log data to the database table named
            &#039;log_table_name&#039; table. The database column named &#039;lvl&#039;
            receives the priority number and the column named &#039;msg&#039; receives the log message.
        </p>
    </div>

    <div class="section" id="zend.log.writers.firebug"><div class="info"><h1 class="title">Writing to Firebug</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Log_Writer_Firebug</span> sends log
        data to the <a href="http://www.getfirebug.com/" class="link external">&raquo; Firebug</a>
        <a href="http://getfirebug.com/logging.html" class="link external">&raquo; Console</a>.
    </p>

    <p class="para">
        <div class="inlinemediaobject"><div class="imageobject"><img src="images/d481d625821a97b9a5eb2cec99dca50e-zend.wildfire.firebug.console.png" alt="zend.wildfire.firebug.console.png" width="310" height="151" /></div></div>
    </p>

    <p class="para">
        All data is sent via the <span class="classname">Zend_Wildfire_Channel_HttpHeaders</span> component
        which uses <acronym class="acronym">HTTP</acronym> headers to ensure the page content is not disturbed.
        Debugging <acronym class="acronym">AJAX</acronym> requests that require clean <acronym class="acronym">JSON</acronym> and
        <acronym class="acronym">XML</acronym> responses is possible with this approach.
    </p>

    <p class="para">
        Requirements:
    </p>

    <ul class="itemizedlist">
        <li class="listitem">
            <p class="para">
                Firefox Browser ideally version 3 but version 2 is also supported.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                Firebug Firefox Extension which you can download from <a href="https://addons.mozilla.org/en-US/firefox/addon/1843" class="link external">&raquo; https://addons.mozilla.org/en-US/firefox/addon/1843</a>.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                FirePHP Firefox Extension which you can download from <a href="https://addons.mozilla.org/en-US/firefox/addon/6149" class="link external">&raquo; https://addons.mozilla.org/en-US/firefox/addon/6149</a>.
            </p>
        </li>
    </ul>

    <div class="example" id="zend.log.writers.firebug.example.with_front_controller"><div class="info"><p><b>Example #1 Logging with Zend_Controller_Front</b></p></div>
        

        <pre class="programlisting brush: php">
// Place this in your bootstrap file before dispatching your front controller
$writer = new Zend_Log_Writer_Firebug();
$logger = new Zend_Log($writer);

// Use this in your model, view and controller files
$logger-&gt;log(&#039;This is a log message!&#039;, Zend_Log::INFO);
</pre>

    </div>

    <div class="example" id="zend.log.writers.firebug.example.without_front_controller"><div class="info"><p><b>Example #2 Logging without Zend_Controller_Front</b></p></div>
        

        <pre class="programlisting brush: php">
$writer = new Zend_Log_Writer_Firebug();
$logger = new Zend_Log($writer);

$request = new Zend_Controller_Request_Http();
$response = new Zend_Controller_Response_Http();
$channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
$channel-&gt;setRequest($request);
$channel-&gt;setResponse($response);

// Start output buffering
ob_start();

// Now you can make calls to the logger

$logger-&gt;log(&#039;This is a log message!&#039;, Zend_Log::INFO);

// Flush log data to browser
$channel-&gt;flush();
$response-&gt;sendHeaders();
</pre>

    </div>

    <div class="section" id="zend.log.writers.firebug.priority-styles"><div class="info"><h1 class="title">Setting Styles for Priorities</h1></div>
        

        <p class="para">
            Built-in and user-defined priorities can be styled with the
             <span class="methodname">setPriorityStyle()</span> method.
        </p>

        <pre class="programlisting brush: php">
$logger-&gt;addPriority(&#039;FOO&#039;, 8);
$writer-&gt;setPriorityStyle(8, &#039;TRACE&#039;);
$logger-&gt;foo(&#039;Foo Message&#039;);
</pre>


        <p class="para">
            The default style for user-defined priorities can be set with the
             <span class="methodname">setDefaultPriorityStyle()</span> method.
        </p>

        <pre class="programlisting brush: php">
$writer-&gt;setDefaultPriorityStyle(&#039;TRACE&#039;);
</pre>


        <p class="para">
            The supported styles are as follows:

            <table id="zend.log.writers.firebug.priority-styles.table" class="doctable table"><div class="info"><caption><b>Firebug Logging Styles</b></caption></div>
                

                
                    <thead valign="middle">
                        <tr valign="middle">
                            <th>Style</th>
                            <th>Description</th>
                        </tr>

                    </thead>


                    <tbody valign="middle" class="tbody">
                        <tr valign="middle">
                            <td align="left"><b><tt>LOG</tt></b></td>
                            <td align="left">Displays a plain log message</td>
                        </tr>


                        <tr valign="middle">
                            <td align="left"><b><tt>INFO</tt></b></td>
                            <td align="left">Displays an info log message</td>
                        </tr>


                        <tr valign="middle">
                            <td align="left"><b><tt>WARN</tt></b></td>
                            <td align="left">Displays a warning log message</td>
                        </tr>


                        <tr valign="middle">
                            <td align="left"><b><tt>ERROR</tt></b></td>

                            <td align="left">
                                Displays an error log message that increments Firebug&#039;s error count
                            </td>
                        </tr>


                        <tr valign="middle">
                            <td align="left"><b><tt>TRACE</tt></b></td>
                            <td align="left">Displays a log message with an expandable stack trace</td>
                        </tr>


                        <tr valign="middle">
                            <td align="left"><b><tt>EXCEPTION</tt></b></td>
                            <td align="left">
                                Displays an error long message with an expandable stack trace
                            </td>
                        </tr>


                        <tr valign="middle">
                            <td align="left"><b><tt>TABLE</tt></b></td>
                            <td align="left">Displays a log message with an expandable table</td>
                        </tr>

                    </tbody>
                
            </table>

        </p>
    </div>

    <div class="section" id="zend.log.writers.firebug.preparing-data"><div class="info"><h1 class="title">Preparing data for Logging</h1></div>
        

        <p class="para">
            While any <acronym class="acronym">PHP</acronym> variable can be logged with the built-in priorities,
            some special formatting is required if using some of the more specialized log styles.
        </p>

        <p class="para">
            The <b><tt>LOG</tt></b>, <b><tt>INFO</tt></b>, <b><tt>WARN</tt></b>,
            <b><tt>ERROR</tt></b> and <b><tt>TRACE</tt></b> styles require no special
            formatting.
        </p>
    </div>

    <div class="section" id="zend.log.writers.firebug.preparing-data.exception"><div class="info"><h1 class="title">Exception Logging</h1></div>
        

        <p class="para">
            To log a <span class="classname">Zend_Exception</span> simply pass the exception object to the
            logger. It does not matter which priority or style you have set as the exception is
            automatically recognized.
        </p>

        <pre class="programlisting brush: php">
$exception = new Zend_Exception(&#039;Test exception&#039;);
$logger-&gt;err($exception);
</pre>

    </div>

    <div class="section" id="zend.log.writers.firebug.preparing-data.table"><div class="info"><h1 class="title">Table Logging</h1></div>
        

        <p class="para">
            You can also log data and format it in a table style. Columns are automatically
            recognized and the first row of data automatically becomes the header.
        </p>

        <pre class="programlisting brush: php">
$writer-&gt;setPriorityStyle(8, &#039;TABLE&#039;);
$logger-&gt;addPriority(&#039;TABLE&#039;, 8);

$table = array(&#039;Summary line for the table&#039;,
             array(
                 array(&#039;Column 1&#039;, &#039;Column 2&#039;),
                 array(&#039;Row 1 c 1&#039;,&#039; Row 1 c 2&#039;),
                 array(&#039;Row 2 c 1&#039;,&#039; Row 2 c 2&#039;)
             )
            );
$logger-&gt;table($table);
</pre>

    </div>
</div>
    <div class="section" id="zend.log.writers.mail"><div class="info"><h1 class="title">Writing to Email</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Log_Writer_Mail</span> writes log entries in an email message
        by using <span class="classname">Zend_Mail</span>. The <span class="classname">Zend_Log_Writer_Mail</span>
        constructor takes a <span class="classname">Zend_Mail</span> object, and an optional
        <span class="classname">Zend_Layout</span> object.
    </p>

    <p class="para">
        The primary use case for <span class="classname">Zend_Log_Writer_Mail</span> is notifying
        developers, systems administrators, or any concerned parties of errors
        that might be occurring with <acronym class="acronym">PHP</acronym>-based scripts.
        <span class="classname">Zend_Log_Writer_Mail</span> was born out of the idea that if
        something is broken, a human being needs to be alerted of it immediately
        so they can take corrective action.
    </p>

    <p class="para">
        Basic usage is outlined below:
    </p>

    <pre class="programlisting brush: php">
$mail = new Zend_Mail();
$mail-&gt;setFrom(&#039;errors@example.org&#039;)
     -&gt;addTo(&#039;project_developers@example.org&#039;);

$writer = new Zend_Log_Writer_Mail($mail);

// Set subject text for use; summary of number of errors is appended to the
// subject line before sending the message.
$writer-&gt;setSubjectPrependText(&#039;Errors with script foo.php&#039;);

// Only email warning level entries and higher.
$writer-&gt;addFilter(Zend_Log::WARN);

$log = new Zend_Log();
$log-&gt;addWriter($writer);

// Something bad happened!
$log-&gt;error(&#039;unable to connect to database&#039;);

// On writer shutdown, Zend_Mail::send() is triggered to send an email with
// all log entries at or above the Zend_Log filter level.
</pre>


    <p class="para">
        <span class="classname">Zend_Log_Writer_Mail</span> will render the email body as plain
        text by default.
    </p>

    <p class="para">
        One email is sent containing all log entries at or above the filter
        level. For example, if warning-level entries an up are to be emailed,
        and two warnings and five errors occur, the resulting email will contain
        a total of seven log entries.
    </p>

    <div class="section" id="zend.log.writers.mail.layoutusage"><div class="info"><h1 class="title">Zend_Layout Usage</h1></div>
        

        <p class="para">
            A <span class="classname">Zend_Layout</span> instance may be used to generate the
            <acronym class="acronym">HTML</acronym> portion of a multipart email. If a
            <span class="classname">Zend_Layout</span> instance is in use,
            <span class="classname">Zend_Log_Writer_Mail</span> assumes that it is being used to render
            <acronym class="acronym">HTML</acronym> and sets the body <acronym class="acronym">HTML</acronym> for the message as
            the <span class="classname">Zend_Layout</span>-rendered value.
        </p>

        <p class="para">
            When using <span class="classname">Zend_Log_Writer_Mail</span> with a
            <span class="classname">Zend_Layout</span> instance, you have the option to set a
            custom formatter by using the  <span class="methodname">setLayoutFormatter()</span>
            method. If no <span class="classname">Zend_Layout</span>-specific entry formatter was
            specified, the formatter currently in use will be used. Full usage
            of <span class="classname">Zend_Layout</span> with a custom formatter is outlined
            below.
        </p>

        <pre class="programlisting brush: php">
$mail = new Zend_Mail();
$mail-&gt;setFrom(&#039;errors@example.org&#039;)
     -&gt;addTo(&#039;project_developers@example.org&#039;);
// Note that a subject line is not being set on the Zend_Mail instance!

// Use a simple Zend_Layout instance with its defaults.
$layout = new Zend_Layout();

// Create a formatter that wraps the entry in a listitem tag.
$layoutFormatter = new Zend_Log_Formatter_Simple(
    &#039;&lt;li&gt;&#039; . Zend_Log_Formatter_Simple::DEFAULT_FORMAT . &#039;&lt;/li&gt;&#039;
);

$writer = new Zend_Log_Writer_Mail($mail, $layout);

// Apply the formatter for entries as rendered with Zend_Layout.
$writer-&gt;setLayoutFormatter($layoutFormatter);
$writer-&gt;setSubjectPrependText(&#039;Errors with script foo.php&#039;);
$writer-&gt;addFilter(Zend_Log::WARN);

$log = new Zend_Log();
$log-&gt;addWriter($writer);

// Something bad happened!
$log-&gt;error(&#039;unable to connect to database&#039;);

// On writer shutdown, Zend_Mail::send() is triggered to send an email with
// all log entries at or above the Zend_Log filter level. The email will
// contain both plain text and HTML parts.
</pre>

    </div>

    <div class="section" id="zend.log.writers.mail.dynamicsubjectline"><div class="info"><h1 class="title">Subject Line Error Level Summary</h1></div>
        

        <p class="para">
            The  <span class="methodname">setSubjectPrependText()</span> method may be used in place
            of  <span class="methodname">Zend_Mail::setSubject()</span> to have the email subject
            line dynamically written before the email is sent. For example, if
            the subject prepend text reads &quot;Errors from script&quot;, the subject of
            an email generated by <span class="classname">Zend_Log_Writer_Mail</span> with two
            warnings and five errors would be &quot;Errors from script (warn = 2;
            error = 5)&quot;. If subject prepend text is not in use via
            <span class="classname">Zend_Log_Writer_Mail</span>, the <span class="classname">Zend_Mail</span>
            subject line, if any, is used.
        </p>
    </div>

    <div class="section" id="zend.log.writers.mail.caveats"><div class="info"><h1 class="title">Caveats</h1></div>
        

        <p class="para">
            Sending log entries via email can be dangerous. If error conditions
            are being improperly handled by your script, or if you&#039;re misusing
            the error levels, you might find yourself in a situation where you
            are sending hundreds or thousands of emails to the recipients
            depending on the frequency of your errors.
        </p>

        <p class="para">
            At this time, <span class="classname">Zend_Log_Writer_Mail</span> does not provide any
            mechanism for throttling or otherwise batching up the messages.
            Such functionality should be implemented by the consumer if
            necessary.
        </p>

        <p class="para">
            Again, <span class="classname">Zend_Log_Writer_Mail</span>&#039;s primary goal is to
            proactively notify a human being of error conditions. If those
            errors are being handled in a timely fashion, and safeguards are
            being put in place to prevent those circumstances in the future,
            then email-based notification of errors can be a valuable tool.
        </p>
    </div>
</div>
    <div class="section" id="zend.log.writers.syslog"><div class="info"><h1 class="title">Writing to the System Log</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Log_Writer_Syslog</span> writes log entries to the
        system log (syslog). Internally, it proxies to <acronym class="acronym">PHP</acronym>&#039;s
         <span class="methodname">openlog()</span>,
         <span class="methodname">closelog()</span>, and
         <span class="methodname">syslog()</span> functions.
    </p>

    <p class="para">
        One useful case for <span class="classname">Zend_Log_Writer_Syslog</span>
        is for aggregating logs from clustered machines via the system log
        functionality. Many systems allow remote logging of system events, which
        allows system administrators to monitor a cluster of machines from a
        single log file.
    </p>

    <p class="para">
        By default, all syslog messages generated are prefixed with the string
        &quot;Zend_Log&quot;. You may specify a different &quot;application&quot; name by which to
        identify such log messages by either passing the application name to the
        constructor or the application accessor:
    </p>

    <pre class="programlisting brush: php">
// At instantiation, pass the &quot;application&quot; key in the options:
$writer = new Zend_Log_Writer_Syslog(array(&#039;application&#039; =&gt; &#039;FooBar&#039;));

// Any other time:
$writer-&gt;setApplicationName(&#039;BarBaz&#039;);
</pre>


    <p class="para">
        The system log also allows you to identify the &quot;facility,&quot; or
        application type, logging the message; many system loggers will actually
        generate different log files per facility, which again aids
        administrators monitoring server activity.
    </p>

    <p class="para">
        You may specify the log facility either in the constructor or via an
        accessor. It should be one of the  <span class="methodname">openlog()</span>
        constants defined on the <a href="http://php.net/openlog" class="link external">&raquo; openlog()
            manual page</a>.
    </p>

    <pre class="programlisting brush: php">
// At instantiation, pass the &quot;facility&quot; key in the options:
$writer = new Zend_Log_Writer_Syslog(array(&#039;facility&#039; =&gt; LOG_AUTH));

// Any other time:
$writer-&gt;setFacility(LOG_USER);
</pre>


    <p class="para">
        When logging, you may continue to use the default
        <span class="classname">Zend_Log</span> priority constants; internally, they are
        mapped to the appropriate  <span class="methodname">syslog()</span> priority
        constants.
    </p>
</div>
    <div class="section" id="zend.log.writers.zendmonitor"><div class="info"><h1 class="title">Writing to the Zend Server Monitor</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Log_Writer_ZendMonitor</span> allows you to log events via Zend
        Server&#039;s Monitor <acronym class="acronym">API</acronym>. This allows you to aggregate log messages for your
        entire application environment in a single location. Internally, it simply uses the
         <span class="methodname">monitor_custom_event()</span> function from the Zend Monitor
        <acronym class="acronym">API</acronym>.
    </p>

    <p class="para">
        One particularly useful feature of the Monitor <acronym class="acronym">API</acronym> is that it allows you
        to specify arbitrary custom information alongside the log message. For instance, if you wish
        to log an exception, you can log not just the exception message, but pass the entire
        exception object to the function, and then inspect the object within the Zend Server event
        monitor.
    </p>

    <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Zend Monitor must be installed and enabled</b><br /></span>
        

        <p class="para">
            In order to use this log writer, Zend Monitor must be both installed and enabled.
            However, it is designed such that if Zend Monitor is not detected, it will simply act as
            a <b><tt>NULL</tt></b> logger.
        </p>
    </p></blockquote>

    <p class="para">
        Instantiating the <span class="classname">ZendMonitor</span> log writer is trivial:
    </p>

    <pre class="programlisting brush: php">
$writer = new Zend_Log_Writer_ZendMonitor();
$log    = new Zend_Log($writer);
</pre>


    <p class="para">
        Then, simply log messages as usual:
    </p>

    <pre class="programlisting brush: php">
$log-&gt;info(&#039;This is a message&#039;);
</pre>


    <p class="para">
        If you want to specify additional information to log with the event, pass that information
        in a second parameter:
    </p>

    <pre class="programlisting brush: php">
$log-&gt;info(&#039;Exception occurred&#039;, $e);
</pre>


    <p class="para">
        The second parameter may be a scalar, object, or array; if you need to pass multiple pieces
        of information, the best way to do so is to pass an associative array.
    </p>

    <pre class="programlisting brush: php">
$log-&gt;info(&#039;Exception occurred&#039;, array(
    &#039;request&#039;   =&gt; $request,
    &#039;exception&#039; =&gt; $e,
));
</pre>


    <p class="para">
        Within Zend Server, your event is logged as a &quot;custom event&quot;. From the &quot;Monitor&quot; tab, select
        the &quot;Events&quot; sub-item, and then filter on &quot;Custom&quot; to see custom events.
    </p>

    <p class="para">
        <div class="inlinemediaobject"><div class="imageobject"><a href="images/d481d625821a97b9a5eb2cec99dca50e-zend.log.writers.zendmonitor-events.png"><img src="images/d481d625821a97b9a5eb2cec99dca50e-zend.log.writers.zendmonitor-events.png" alt="zend.log.writers.zendmonitor-events.png" width="450" height="298" /></a></div></div>
    </p>

    <p class="para">
        Events in Zend Server&#039;s Monitor dashboard
    </p>

    <p class="para">
        In this screenshot, the first two events listed are custom events logged via the
        <span class="classname">ZendMonitor</span> log writer. You may then click on an event to view all
        information related to it.
    </p>

    <p class="para">
        <div class="inlinemediaobject"><div class="imageobject"><a href="images/d481d625821a97b9a5eb2cec99dca50e-zend.log.writers.zendmonitor-event.png"><img src="images/d481d625821a97b9a5eb2cec99dca50e-zend.log.writers.zendmonitor-event.png" alt="zend.log.writers.zendmonitor-event.png" width="450" height="298" /></a></div></div>
    </p>

    <p class="para">
        Event detail in Zend Server&#039;s Monitor
    </p>

    <p class="para">
        Clicking on the &quot;Custom&quot; sub tab will detail any extra information you logged by passing the
        second argument to the logging method. This information will be logged as the
        <var class="varname">info</var> subkey; you can see that the request object was logged in this
        example.
    </p>

    <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Integration with Zend_Application</b><br /></span>
        

        <p class="para">
            By default, the <strong class="command">zf.sh</strong> and <strong class="command">zf.bat</strong> commands add
            configuration for the <a href="zend.application.available-resources.html#zend.application.available-resources.log" class="link"><span class="classname">Zend_Application</span>
                log resource</a>, which includes configuration for the
            <span class="classname">ZendMonitor</span> log writer. Additionally, the
            <span class="classname">ErrorController</span> uses the configured logger to log application
            exceptions -- providing you with Zend Monitor event integration by default.
        </p>

        <p class="para">
            As noted previously, if the Monitor <acronym class="acronym">API</acronym> is not detected in your
            <acronym class="acronym">PHP</acronym> installation, the logger will simply act as a
            <b><tt>NULL</tt></b> logger.
        </p>
    </p></blockquote>
</div>

    <div class="section" id="zend.log.writers.null"><div class="info"><h1 class="title">Stubbing Out the Writer</h1></div>
        

        <p class="para">
            The <span class="classname">Zend_Log_Writer_Null</span> is a stub that does not write log data
            to anything. It is useful for disabling logging or stubbing out logging during tests:
        </p>

        <pre class="programlisting brush: php">
$writer = new Zend_Log_Writer_Null;
$logger = new Zend_Log($writer);

// goes nowhere
$logger-&gt;info(&#039;Informational message&#039;);
</pre>

    </div>

    <div class="section" id="zend.log.writers.mock"><div class="info"><h1 class="title">Testing with the Mock</h1></div>
        

        <p class="para">
            The <span class="classname">Zend_Log_Writer_Mock</span> is a very simple writer that records
            the raw data it receives in an array exposed as a public property.
        </p>

        <pre class="programlisting brush: php">
$mock = new Zend_Log_Writer_Mock;
$logger = new Zend_Log($mock);

$logger-&gt;info(&#039;Informational message&#039;);

var_dump($mock-&gt;events[0]);

// Array
// (
//    [timestamp] =&gt; 2007-04-06T07:16:37-07:00
//    [message] =&gt; Informational message
//    [priority] =&gt; 6
//    [priorityName] =&gt; INFO
// )
</pre>


        <p class="para">
            To clear the events logged by the mock, simply set
            <strong class="command">$mock-&gt;events = array()</strong>.
        </p>
    </div>

    <div class="section" id="zend.log.writers.compositing"><div class="info"><h1 class="title">Compositing Writers</h1></div>
        

        <p class="para">
            There is no composite Writer object. However, a Log instance can write
            to any number of Writers. To do this, use the  <span class="methodname">addWriter()</span>
            method:
        </p>

        <pre class="programlisting brush: php">
$writer1 = new Zend_Log_Writer_Stream(&#039;/path/to/first/logfile&#039;);
$writer2 = new Zend_Log_Writer_Stream(&#039;/path/to/second/logfile&#039;);

$logger = new Zend_Log();
$logger-&gt;addWriter($writer1);
$logger-&gt;addWriter($writer2);

// goes to both writers
$logger-&gt;info(&#039;Informational message&#039;);
</pre>

    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.log.overview.html">Overview</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.log.html">Zend_Log</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.log.formatters.html">Formatters</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="reference.html">Refer&ecirc;ncia do Zend Framework</a></li>
  <li class="header up"><a href="zend.log.html">Zend_Log</a></li>
  <li><a href="zend.log.overview.html">Overview</a></li>
  <li class="active"><a href="zend.log.writers.html">Writers</a></li>
  <li><a href="zend.log.formatters.html">Formatters</a></li>
  <li><a href="zend.log.filters.html">Filters</a></li>
  <li><a href="zend.log.factory.html">Using the Factory to Create a Log</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>